<?php
/**
 * Created by PhpStorm.
 * User: zk
 * Date: 2018/10/24
 * Time: 下午1:55
 */
use app\assets\AppAsset;
use app\common\CommonHelper;

$base = Yii::$app->request->baseUrl;
AppAsset::addCss($this,$base . '/app/css/dynamic-detail.css');

AppAsset::addCss($this,$base . '/app/css/skin/jedate.css');
AppAsset::addScript($this,$base . '/app/js/jedate.js');
AppAsset::addScript($this,$base . '/app/js/app-js.js');

$model = new CommonHelper();

$tomorrowDate = $model->getTomorrowDateHI();
$yesterdayDate = $model->getYesterdayDateHI();
?>

<div class="search-box">
    <div style="margin-left: 1.67rem;">
        <span class="date-split">申请时间：</span>
        <p class="datep">
            <img src="<?=$base?>/app/images/new/rc_icon_date.png" class="date-icon">
            <input class="datainp" id="datebut" type="text" placeholder="请选择"  readonly>

        </p>

        <span class="date-split">至</span>

        <p class="datep">

            <img src="<?=$base?>/app/images/new/rc_icon_date.png" class="date-icon">
            <input class="datainp" id="datebut2" type="text" placeholder="请选择"  readonly>
        </p>
    </div>
    

    <div class="dropdown" style="margin-left:1.67rem;font-size: 1.3rem;float: left">
        <button type="button" class="btn dropdown-toggle" id="dropdownMenu"
                data-toggle="dropdown">
            审核状态
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusStatus('所有状态',-1)">所有状态</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusStatus('未审核',0)">未审核</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusStatus('通过',1)">通过</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusStatus('未通过',2)">未通过</a>
            </li>
        </ul>
    </div>

    <div class="dropdown" style="margin-left:1.67rem;font-size: 1.3rem;float: left">
        <button type="button" class="btn dropdown-toggle" id="dropdownMenu2"
                data-toggle="dropdown">
            商家类型
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu2">
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusType('所有类型',-1)">所有类型</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusType('清吧',1)">清吧</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusType('夜店',2)">夜店</a>
            </li>
            <li role="presentation" >
                <a role="menuitem" tabindex="-1" href="javascript:chooseBusType('livehouse',3)"> livehouse</a>
            </li>

        </ul>
    </div>

    <!-- <select id="cityID" style="margin-left: 1.67rem;float: left;" onchange="searchFunction()">
        <option value="-1">所在城市</option>
        <option value="179">杭州市</option>
        <?php for($index=0;$index<count($cities);$index++){?>
            <option value="<?= $cities[$index]['city_code']?>"><?= $cities[$index]['city_name']?></option>
        <?php }?>
    </select> -->
    <div style="clear:both;"></div>
    <div  style="margin-left: 1.67rem; margin-top: 1.67rem;">
        <span class="date-split">审核时间：</span>
        <p class="datep">
            <img src="<?=$base?>/app/images/new/rc_icon_date.png" class="date-icon">
            <input class="datainp" id="datebut3" type="text" placeholder="请选择"  readonly>

        </p>

        <span class="date-split">至</span>

        <p class="datep">

            <img src="<?=$base?>/app/images/new/rc_icon_date.png" class="date-icon">
            <input class="datainp" id="datebut4" type="text" placeholder="请选择"  readonly>
        </p>
    </div>
    

    <div class="datep" style="margin-left: 1.67rem;"><input id="nameId" class="name-input" placeholder="请输入酒吧名"></div>

    <img id="search-img" onclick="searchFunction()" class="search-icon" style="margin-left: 1rem;" src="<?=$base?>/app/images/new/rc_btn_search_n.png">

<!--    <div class="button-div" style="margin-left: 3.6rem" onclick="goToDetail()">新增</div>-->

    <div style="clear:both;"></div>
</div>

<div class="table-box" style="background: none">
    <table id="table" style="background: #FFFFFF;"></table>

    <div class="showContent" id="show_content" style="position: absolute;display: none;">
        <span class="content" id="content_id">test</span>
    </div>
</div>

<script>
    var tomorrowDate = '<?php echo $tomorrowDate?>';
    var yesterdayDate = '<?php echo $yesterdayDate?>';
    $("#datebut").val("2018-09-01 00:00");
    $("#datebut2").val(tomorrowDate);
    $("#datebut3").val("2018-09-01 00:00");
    $("#datebut4").val(tomorrowDate);
    window.onload=function () {
    var start = {
        format: 'YYYY-MM-DD hh:mm',
        minDate: '2016-8-8 12:00', //设定最小日期为当前日期
        skinCell:"jedateblue",
        festival:false,
        isTime:true,
        isToday:false,
        isClear:false,
        maxDate: '2099-06-30 12:00', //最大日期
        choosefun: function(elem,datas){
            end.minDate = datas; //开始日选好后，重置结束日的最小日期
        }
    };
    var end = {
        format: 'YYYY-MM-DD hh:mm',
        skinCell:"jedateblue",
        minDate: '2016-8-8 12:00', //设定最小日期为当前日期
        festival:false,
        isTime:true,
        isToday:false,
        isClear:false,
        maxDate: '2099-06-16 12:00', //最大日期
        choosefun: function(elem,datas){
            start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    $.jeDate('#datebut',start);
    $.jeDate('#datebut2',end);
    $.jeDate('#datebut3',start);
    $.jeDate('#datebut4',end);
};

    //初始化表格设置
    $('#table').bootstrapTable({
        toolbar: '#toolbar',        //工具按钮用哪个容器
        clickToSelect: true,//点击行即可选中单选/复选框
        singleSelect: false,//复选框只能选择一条记录
        search: false,//是否显示右上角的搜索框
        striped: true,      //是否显示行间隔色
        cache: false,            //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        sidePagination: "server", //服务端处理分页
        pagination: true,     //是否显示分页（*）
        sortable: false,           //是否启用排序
        sortOrder: "asc",          //排序方式
        method: 'GET',      //请求方式（*）
        pageNumber:1,      //初始化加载第一页，默认第一页
        pageSize: 8,      //每页的记录行数（*）
//        pageList: [10, 20, 50, 100],  //可供选择的每页的行数（*）
        cardView: false,          //是否显示详细视图
        queryParams:setParams,
        uniqueId:'claim_id',
        url:'business',
        responseHandler:dataProcess,

        columns: [{
            field: 'bar.bar_id',
            align: 'center',
            valign: 'middle',
            title: '商家ID'
        },{
            field: '',
            align: 'center',
            valign: 'middle',
            title: '申请商家',
            formatter:function(value,row,index) {
                console.log(row);
                return '<span style="color: #0000ff" onclick="goToDetail('+row.bar.bar_id+')">'+row.bar.bar_name+'</span>';
            }
        },{
            field: '',
            align: 'center',
            valign: 'middle',
            title: '城市',
            formatter:function(value,row,index) {
                return row.bar.bar_address?row.bar.bar_address:"无";
            }
        },{
            field: '',
            align: 'center',
            valign: 'middle',
            title: '类型',
            formatter:function(value,row,index) {
                return row.bar.bar_type == 1 ? "清吧" : row.bar.bar_type == 2 ? "夜店" : "livehouse"
            }
        },{
            field: '',
            align: 'center',
            valign: 'middle',
            title: '状态',
            formatter:function(value,row,index) {
                return row.is_pass == 0 ? "待审核" : row.is_pass == 1? "通过" : "未通过";
            }
        },{
            field: 'claim_name',
            align: 'center',
            valign: 'middle',
            title: '认领人姓名'
        },{
            field: 'claim_mobile',
            align: 'center',
            valign: 'middle',
            title: '认领人电话'
        },{
            field: '',
            align: 'center',
            valign: 'middle',
            title: '操作',
            formatter:function(value,row,index) {
                var html = "";
                if(row.is_pass == 0){
                    html = '<div class="button-div" onclick="operateController.operateFunc('+row.bar_id+','+row.claim_id+',1)">通过</div> <div class="button-div" onclick="operateController.operateFunc('+row.bar_id+','+row.claim_id+',2)">不通过</div>';
                }else if(row.is_pass == 1) {
                    html = '已通过';
                } else {
                    html = '已否决';
                }

                return html;
            }
        }]
    });

    function dataProcess(res){
        var data = res;
        return {
            'rows':data.rows,
            'total':data.total
        }
    }

    var busStatus = -1;
    var busType = -1;

    function setParams(params){
        var start_date = $('#datebut').val(); //按日期搜索
        var end_date = $('#datebut2').val();

        if (start_date == "2018-09-01 00:00") {
            var start_date = undefined; //按日期搜索
            var end_date = undefined;
        }

        if (start_date && start_date != undefined && end_date && end_date != undefined){
            params.start_date = start_date;
            params.end_date = end_date;
        }

        var examine_start = $('#datebut3').val(); //按日期搜索
        var examine_end = $('#datebut4').val();

        if (examine_start == "2018-09-01 00:00") {
            var examine_start = undefined; //按日期搜索
            var examine_end = undefined;
        }

        if (examine_start && examine_start != undefined && examine_end && examine_end != undefined){
            params.examine_start = examine_start;
            params.examine_end = examine_end;
        }

        if (busStatus != -1)
            params.is_pass = busStatus;

        if (busType != -1) {
            params.bar_type = busType;
        }

        var content = $("#nameId").val();
        if (content && content != undefined && content.length > 0)
            params.bar_name = content;

        return params;
    }

    function chooseBusStatus(name,status){
        busStatus = status;
        $("#dropdownMenu").text(name);
        $('#table').bootstrapTable('refreshOptions', {pageNumber: 1});
    }

    function chooseBusType(name, type){
        busType = type;
        $("#dropdownMenu2").text(name);
        $('#table').bootstrapTable('refreshOptions', {pageNumber: 1});
    }

    function searchFunction(){
        $('#table').bootstrapTable('refreshOptions', {pageNumber: 1});
    }

    var operateController = {
        operateApi : "bus-pass",
        // 审核商家入驻
        operateFunc:function(bar_id, claim_id , status){
            if (status == 1) {
                if(confirm("确认通过该商家？")){
                    var param = {
                        claim_id:claim_id,
                        status:status,
                        bar_id:bar_id
                    };

                    sendAjax(this.operateApi,"POST",param,true,function(res){
                        var data = JSON.parse(res);
                        if(data.code == 0){
                            $('#table').bootstrapTable('refresh');
                        } else if(data.code == 2) {
                            alert(data.msg);
                        } else {
                            alert(data.msg);
                        }
                    });
                }
            } else {
                if(confirm("确认驳回该商家？")){
                    var param = {
                        claim_id:claim_id,
                        status:status
                    };

                    sendAjax(this.operateApi,"POST",param,true,function(res){
                        var data = JSON.parse(res);
                        if(data.code == 0)
                            $('#table').bootstrapTable('refresh');
                    });
                }
            }
            
        }
    };

    function setWeight(view){
//        var barId = $(view).attr("barid");
//        console.log(barId);
        weightController.weightFunc($(view).attr("barid"),$(view).val());
    }

    var weightController = {
        weightApi : "bar",
        weightFunc:function(bar_id , weight){
            var param = {
                bar_id:bar_id,
                weight_value:weight
            };

            sendAjax(this.weightApi,"POST",param,true,function(res){
                var data = JSON.parse(res);
                if(data.code == 0)
                    $('#table').bootstrapTable('refresh');
            });
        }
    };

    function goToDetail(barId){
        window.open("bar-detail?bar_id="+barId);
    }

    function goToAddDynamic(barId){
        window.open("add-dynamic?bar_id="+barId);
    }
</script>

